<?php

/**
 * Abstract class describing a standard uAdmin page.
 * @author Eyas
 */
abstract class Page {
	private $parent;
	private $children;
	private $title;
	private $nodeName;

	public function __construct($nodeName, $title) {
		$this->children = Array();
		$this->nodeName = $nodeName;
		$this->title = $title;
	}

	/**
	 * Add a child to this Page
	 * @param Page $child
	 */
	public function addChild(Page $child) {
		$this->children[$child->getNode()] = $child;
		$child->setParent($this);
	}

	/**
	 * Get the child of the current page with a given title
	 * @param string $pageTitle
	 */
	public function getChild($nodeName) {
		return $this->children[$nodeName];
	}

	/**
	 * Get a mapping of titles to pages for all children of the current page
	 */
	public function getChildren() {
		return $this->children;
	}

	/**
	 * Sets the parent of the current Page to $parent
	 * @param Page $parent
	 */
	public function setParent(Page $parent) {
		$this->parent = $parent;
	}

	/**
	 * Gets the parent of the current Page
	 * @return Page
	 */
	public function getParent() {
		return $this->parent;
	}

	/**
	 * Gets the title of the current Page
	 */
	public function getTitle() {
		return $this->title;
	}
	
	/**
	 * Returns the full title of the page and its parents
	 */
	public function getFulltitle() {
		if (isset($this->parent)) {
			return $this->title . " - " . $this->parent->getFulltitle();
		} else {
			return $this->title;
		}
	}
	
	/**
	 * Gets the node name of the current Page
	 */
	public function getNode() {
		return $this->nodeName;
	}

	/**
	 * Sets the title of the current Page
	 * @param string $title
	 */
	public function setTitle($title) {
		$this->title = $title;
	}

	/**
	 * Gets the URL in which this page can be accessed
	 */
	abstract public function getURL();

}

class ContentPage extends Page {

	public function __cosntruct($nodeName, $title) {
		parent::__construct($nodeName, $title);
	}
	
	public function getURL() {
		return $this->getParent()->getURL() . "/" . $nodeName;
	}
	
	public function getContent() {
		
	}

}

class RootPage extends Page {
	public function __construct($title) {
		parent::_construct("", $title);
	}
	
	public function getURL() {
		return "/";
	}
}
?>